﻿#include <QDebug>

#include "common/AVAudioConvert.h"

#include "AVFileStoreAbstract.h"

AVFileStoreAbstract::AVFileStoreAbstract(QObject *parent) : QObject(parent)
{
    av_register_all();
}

AVFileStoreAbstract::~AVFileStoreAbstract()
{
}

bool AVFileStoreAbstract::resample(AVFrame *frame,uint8_t *buf,int *bytes,int *sampleSize)
{
    /*因为传入数据可能多种多样，故需要做统一转码*/
    int key = frame->sample_rate + frame->channels + frame->format;
    if (!m_converts.contains(key)) {
        m_converts[key] = new AVAudioConvert(frame->sample_rate,frame->channels,frame->format,
                                        m_defaultSampleRate,m_defaultChannels,m_defaultFormat);
    }

    if (m_converts[key]->audio_rescale(frame,buf,bytes,sampleSize) < 0) {
        qDebug() << "resample error";
        return false;
    }

    return true;
}
